using System.Data.Entity.ModelConfiguration;
using PhoneBook.Core.Domain.Contacts;

namespace PhoneBook.Data.Mapping
{
    public class ContactMap : EntityTypeConfiguration<Contact>
    {
        public ContactMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.UserName)
                .HasMaxLength(1000);

            this.Property(t => t.Memo)
                .HasMaxLength(1000);

            // Table & Column Mappings
            this.ToTable("Contact");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.UserName).HasColumnName("UserName");
            this.Property(t => t.Memo).HasColumnName("Memo");
            //this.Property(t => t.Contact_Id).HasColumnName("Contact_Id");

            // Relationships
            this.HasOptional(t => t.ParentContact)
                .WithMany(t => t.ChildContacts);
                //.HasForeignKey(d => d.Contact_Id);

        }
    }
}
